﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class Admin_qxgl2 : System.Web.UI.Page
{
    DataClassesDataContext db1 = new DataClassesDataContext();
    public int? username = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack == true)
        {
            MultiView1.SetActiveView(View1);
            Button3.ForeColor = Color.Red;
            Bindata1();
        }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View2);
        Bindata2();
        Button4.ForeColor = Color.Red;
        Button3.ForeColor = Color.White;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
        Bindata1();
        Button3.ForeColor = Color.Red;
        Button4.ForeColor = Color.White;
    }
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lbl = (Label)e.Row.Cells[0].FindControl("Label2");
            lbl.Text = (GridView2.PageIndex * GridView2.PageSize + e.Row.RowIndex + 1).ToString();
        }
    }
    private void Bindata2()
    {
        GridView3.DataSourceID = "";
        int userName = Convert.ToInt32(Session["username"].ToString());
        username = Convert.ToInt32(Request.QueryString["id"].ToString().Trim());
        var Autority2 = (from p in db1.proc_GetAdminHaveAutority(userName,username)
                           select p).ToList();
            GridView3.DataSource = Autority2;
            GridView3.DataBind();
    }
    private void Bindata1()
    {
        GridView2.DataSourceID = "";
        int userName = Convert.ToInt32(Session["username"].ToString());
        username = Convert.ToInt32(Request.QueryString["id"].ToString());
        var Autority1 = (from p in db1.proc_GetAdminAutorityToAdmin(username, userName)
                           select p).ToList();
        GridView2.DataSource = Autority1;
        GridView2.DataBind();
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        username = Convert.ToInt32(Request.QueryString["id"].ToString());
        for (int i = 0; i <= GridView2.Rows.Count - 1; i++)
        {
            System.Web.UI.WebControls.CheckBox checkbox1 = (System.Web.UI.WebControls.CheckBox)GridView2.Rows[i].FindControl("CheckBox1");
            if (checkbox1.Checked == true)
            {
                string id = GridView2.DataKeys[i].Value.ToString();
                int id1 = Convert.ToInt32(id);
                db1.proc_UpdateAdminAutority(username, id1, 1);
                //Response.Write(id1);
            }
        }
        //MultiView1.SetActiveView(View1);
        Bindata1();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        username = Convert.ToInt32(Request.QueryString["id"].ToString());
        for (int i = 0; i <= GridView3.Rows.Count - 1; i++)
        {
            System.Web.UI.WebControls.CheckBox checkbox1 = (System.Web.UI.WebControls.CheckBox)GridView3.Rows[i].FindControl("CheckBox2");
            if (checkbox1.Checked == true)
            {
                string id = GridView3.DataKeys[i].Value.ToString();
                int id1 = Convert.ToInt32(id);
                db1.proc_UpdateAdminAutority(username, id1, 0);
            }
        }
        //MultiView1.SetActiveView(View2);
        Bindata2();
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
 
    }
}